<script lang="ts" setup>
import { getMedicalListService } from '@/api/medicine'
import { OrderType } from '@/enums'
import type { PageParams } from '@/types/consult'
import type { MedicalOrderItem } from '@/types/medicine'
import MedicineItem from '@/views/medicine/components/medicineItem.vue'
import { ref } from 'vue'
const props = defineProps<{
  status: OrderType
}>()
const params = ref<PageParams & { status: OrderType }>({
  current: '1',
  pageSize: '10',
  status: props.status,
})
const list = ref<MedicalOrderItem[]>([])
const getMedicalList = async () => {
  loading.value = true
  const { rows, pageTotal } = await getMedicalListService(params.value)
  list.value.push(...rows)
  loading.value = false
  params.value.current = (Number(params.value.current) + 1).toString()
  if (pageTotal < Number(params.value.current)) {
    finished.value = true
  }
}
const loading = ref(false)
const finished = ref(false)
</script>

<template>
  <div class="order-list">
    <van-list
      @load="getMedicalList"
      :loading="loading"
      :finished="finished"
      finished-text="没有更多了~"
    >
      <medicine-item v-for="item in list" :key="item.id" :item="item"></medicine-item>
    </van-list>
  </div>
</template>

<style lang="scss" scoped>
.order-list {
  min-height: 600px;
}
</style>
